package com.techsoul.module.pms.controller;

import com.techsoul.common.core.pojo.Result;
import com.techsoul.common.core.pojo.vo.UserVo;
import com.techsoul.common.core.util.ServletUtils;
import com.techsoul.common.core.util.lang.DateUtils;
import com.techsoul.common.security.service.TokenService;
import com.techsoul.module.pms.pojo.param.PmsBirdWatchSaveParam;
import com.techsoul.module.pms.pojo.param.PmsBirdWatchSearchParam;
import com.techsoul.module.pms.service.IPmsBirdWatchService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.validation.Valid;
import java.util.Arrays;
import java.util.Date;

/**
 * 鸟类观测识别统计 Controller
 *
 * @author liuen
 * @date 2021-12-08
 */
@Api(tags = "鸟类观测识别统计")
@RestController
@RequestMapping("/watch/pmsBirdWatch")
public class PmsBirdWatchController {

    @Autowired
    private Result result;
    
    @Autowired
    private IPmsBirdWatchService service;
    @Autowired
    private TokenService tokenService;
    @ApiOperation("新增")
    @PreAuthorize("hasAnyAuthority('watch:pmsBirdWatch:insert')")
    @PostMapping
    public Result insert(@Valid @RequestBody PmsBirdWatchSaveParam params) {
        return result.success(this.service.insert(params));
    }
    @ApiOperation("接口输入")
    @PostMapping("/insertByHaikang")
    public Result insertByHaikang(@Valid @RequestBody PmsBirdWatchSaveParam params) {
        return result.success(this.service.insertByHaikang(params));
    }
    @ApiOperation("导入模板")
    @PreAuthorize("hasAnyAuthority('watch:pmsBirdWatch:update')")
    @PostMapping("/importTemplate")
    public Result importTemplate() {
        return result.success(this.service.importTemplate());
    }

    @ApiOperation("巡护导入")
    @PostMapping("/importData")
    public Result importData(Date applyDate,String area, MultipartFile file) {
        return result.success(this.service.importData(applyDate,area, file));
    }
    @ApiOperation("批量删除（多个用逗号隔开）")
    @PreAuthorize("hasAnyAuthority('watch:pmsBirdWatch:delete')")
    @DeleteMapping("/{ids}")
    public Result batchDelete(@PathVariable String[] ids) {
        return result.success(this.service.batchDelete(Arrays.asList(ids)));
    }

    @ApiOperation("修改")
    @PreAuthorize("hasAnyAuthority('watch:pmsBirdWatch:update')")
    @PutMapping
    public Result update(@Valid @RequestBody PmsBirdWatchSaveParam params) {
        return result.success(this.service.update(params));
    }

    @ApiOperation("详情")
    @PreAuthorize("hasAnyAuthority('watch:pmsBirdWatch:search')")
    @GetMapping("/{id}")
    public Result findById(@PathVariable("id") String id) {
        return result.success(this.service.findById(id));
    }

    @ApiOperation("列表")
    @PreAuthorize("hasAnyAuthority('watch:pmsBirdWatch:search')")
    @PostMapping("/search")
    public Result findAll(@RequestBody PmsBirdWatchSearchParam params) {
        return result.success(this.service.findAll(params));
    }

    @ApiOperation("列表-分页")
    @PreAuthorize("hasAnyAuthority('watch:pmsBirdWatch:search')")
    @PostMapping("/search/{current}/{pageSize}")
    public Result findAll(@RequestBody PmsBirdWatchSearchParam params, @PathVariable Integer current, @PathVariable Integer pageSize) {
        return result.success(this.service.findAll(params, current, pageSize));
    }
    @ApiOperation("抓拍不明鸟类数")
    @PreAuthorize("hasAnyAuthority('watch:pmsBirdWatch:search')")
    @PostMapping("/countTotalBird")
    public Result countTotalBird() {
        UserVo sysUser = tokenService.getLoginUser(ServletUtils.getRequest()).getUser();
        PmsBirdWatchSearchParam pmsBirdWatchSearchParam = new PmsBirdWatchSearchParam();
      //  String year =  DateUtils.getYear();
     //   String mon = DateUtils.getMonth();

      //  String thismon = year.concat("-").concat(mon);
      //  accApSkuMonthlySettlementSearchParam.setJobMonth(thismon);
        pmsBirdWatchSearchParam.setBirdCategory("none");
        return result.success(this.service.countTotalBird(pmsBirdWatchSearchParam));
    }
    @ApiOperation("抓拍勺嘴鹬数")
    @PreAuthorize("hasAnyAuthority('watch:pmsBirdWatch:search')")
    @PostMapping("/countTotalSaoZuiWu")
    public Result countTotalSaoZuiWu() {
        UserVo sysUser = tokenService.getLoginUser(ServletUtils.getRequest()).getUser();
        PmsBirdWatchSearchParam pmsBirdWatchSearchParam = new PmsBirdWatchSearchParam();
        pmsBirdWatchSearchParam.setBirdName("勺嘴鹬");
        return result.success(this.service.countTotalBird(pmsBirdWatchSearchParam));
    }
    @ApiOperation("抓拍大杓鹬数")
    @PreAuthorize("hasAnyAuthority('watch:pmsBirdWatch:search')")
    @PostMapping("/countDaShaoWu")
    public Result countDaShaoWu() {
        UserVo sysUser = tokenService.getLoginUser(ServletUtils.getRequest()).getUser();
        PmsBirdWatchSearchParam pmsBirdWatchSearchParam = new PmsBirdWatchSearchParam();
        pmsBirdWatchSearchParam.setBirdName("大杓鹬");
        return result.success(this.service.countTotalBird(pmsBirdWatchSearchParam));
    }
    @ApiOperation("抓拍黑脸鹜数")
    @PreAuthorize("hasAnyAuthority('watch:pmsBirdWatch:search')")
    @PostMapping("/countTotalHeilianwu")
    public Result countTotalHeilianwu() {
        UserVo sysUser = tokenService.getLoginUser(ServletUtils.getRequest()).getUser();
        PmsBirdWatchSearchParam pmsBirdWatchSearchParam = new PmsBirdWatchSearchParam();
        pmsBirdWatchSearchParam.setBirdName("黑脸鹜");
        return result.success(this.service.countTotalBird(pmsBirdWatchSearchParam));
    }
    @ApiOperation("昨日抓拍不明鸟类数")
    @PreAuthorize("hasAnyAuthority('watch:pmsBirdWatch:search')")
    @PostMapping("/countTotaltoday")
    public Result countTotaltoday() {
        UserVo sysUser = tokenService.getLoginUser(ServletUtils.getRequest()).getUser();
        PmsBirdWatchSearchParam pmsBirdWatchSearchParam = new PmsBirdWatchSearchParam();

        Date yesterday = DateUtils.getDateBefore(new Date(),1);
        String ystDay = DateUtils.formatDate(yesterday);
        pmsBirdWatchSearchParam.setCtDate(ystDay);
        pmsBirdWatchSearchParam.setBirdCategory("none");
        return result.success(this.service.countTotalBird(pmsBirdWatchSearchParam));
    }
    @ApiOperation("昨天黑脸鹜数")
    @PreAuthorize("hasAnyAuthority('watch:pmsBirdWatch:search')")
    @PostMapping("/countTodayHeilianwu")
    public Result countTodayHeilianwu() {
        UserVo sysUser = tokenService.getLoginUser(ServletUtils.getRequest()).getUser();
        PmsBirdWatchSearchParam pmsBirdWatchSearchParam = new PmsBirdWatchSearchParam();
        pmsBirdWatchSearchParam.setBirdName("黑脸鹜");
        Date yesterday = DateUtils.getDateBefore(new Date(),1);
        String ystDay = DateUtils.formatDate(yesterday);
        pmsBirdWatchSearchParam.setCtDate(ystDay);
        return result.success(this.service.countTotalBird(pmsBirdWatchSearchParam));
    }
    @ApiOperation("抓拍大杓鹬数")
    @PreAuthorize("hasAnyAuthority('watch:pmsBirdWatch:search')")
    @PostMapping("/countTodayDaShaoWu")
    public Result countTodayDaShaoWu() {
        UserVo sysUser = tokenService.getLoginUser(ServletUtils.getRequest()).getUser();
        PmsBirdWatchSearchParam pmsBirdWatchSearchParam = new PmsBirdWatchSearchParam();
        pmsBirdWatchSearchParam.setBirdName("大杓鹬");
        Date yesterday = DateUtils.getDateBefore(new Date(),1);
        String ystDay = DateUtils.formatDate(yesterday);
        return result.success(this.service.countTotalBird(pmsBirdWatchSearchParam));
    }
    @ApiOperation("抓拍勺嘴鹬数")
    @PreAuthorize("hasAnyAuthority('watch:pmsBirdWatch:search')")
    @PostMapping("/countTodaySaoZuiWu")
    public Result countTodaySaoZuiWu() {
        UserVo sysUser = tokenService.getLoginUser(ServletUtils.getRequest()).getUser();
        PmsBirdWatchSearchParam pmsBirdWatchSearchParam = new PmsBirdWatchSearchParam();
        pmsBirdWatchSearchParam.setBirdName("勺嘴鹬");
        Date yesterday = DateUtils.getDateBefore(new Date(),1);
        String ystDay = DateUtils.formatDate(yesterday);
        return result.success(this.service.countTotalBird(pmsBirdWatchSearchParam));
    }
    @ApiOperation("统计")
    @PreAuthorize("hasAnyAuthority('watch:pmsBirdWatch:search')")
    @PostMapping("/countBirdStats")
    public Result countBirdStats(@RequestBody PmsBirdWatchSearchParam params) {


        return result.success(this.service.countBirdStats(params));
    }

    @ApiOperation("鸟类识别")
    @PreAuthorize("hasAnyAuthority('watch:pmsBirdWatch:search')")
    @PostMapping("/countBarData")
    public Result countBarData() {
        UserVo sysUser = tokenService.getLoginUser(ServletUtils.getRequest()).getUser();


        return result.success(this.service.countBarData());
    }

    @ApiOperation("导出")
    @PreAuthorize("hasAnyAuthority('watch:pmsBirdWatch:search')")
    @PostMapping("/exportData")
    public Result exportData(@RequestBody PmsBirdWatchSearchParam params) {
        return result.success(this.service.exportData(params));
    }


}
